import request from '@/utils/request'
import {proxyPrefix} from '../utils/index'

//form表单形式
export function login(account, pwd,isRemember) {
  const data = {
    userName: account,
    password: pwd,
    ifRemember: isRemember
  }
  return request({
    url: proxyPrefix + '/login',
    method: 'post',
    data: data,
    transformRequest: [
      function (data) {
        let ret = ''
        for (let it in data) {
          ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
        }
        ret = ret.substring(0, ret.lastIndexOf('&'));
        return ret
      }
    ],
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    }
  })
}

export function getInfo(token) {
  const data = {
    token: token
  }
  return request({
    url: proxyPrefix + '/user/tokenUserInfo',
    method: 'post',
    data
  })
}

export function logout(token) {
  return request({
    url: proxyPrefix + '/logout',
    method: 'post'
  })
}
